package com.itheima.dao.Impl;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import com.itheima.utils.DruidUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    //创建jdbcTemplate模板
    private JdbcTemplate jt = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public List<User> findAll(Integer pageNum) {



        return jt.query("select * from hero limit ?,3",
                new BeanPropertyRowMapper<User>(User.class),(pageNum-1)*3);
    }


    @Override
    public Long findCount() {
        return jt.queryForObject("select count(*) from hero",Long.class);
    }
}
